package bjfuwjx.exp4;

import java.util.concurrent.CopyOnWriteArrayList;

public class BallMove extends Thread{
    public CopyOnWriteArrayList<Ball> list1,list2;
    public MyPanel ballPanel;
    boolean IsStop=true;
    public BallMove(CopyOnWriteArrayList list1,CopyOnWriteArrayList list2,MyPanel ballPanel) {
        this.list1=list1;
        this.list2=list2;
        this.ballPanel = ballPanel;
    }
    @Override
    public void run() throws NullPointerException{
        while (true) {
            if (!IsStop) {
                if (list1.size()!=0||list2.size()!=0) {
                    for(int i=0;i<list1.size();i++) {
                        list1.get(i).move_left();
                        ballPanel.repaint();
                        if (list1.get(i).x<=-40){
                            list1.remove(i);
                        }
                    }
                    for (int i=0;i<list2.size();i++){
                        list2.get(i).move_right();
                        ballPanel.repaint();
                        if (list2.get(i).x>=1000){
                            list2.remove(i);
                        }
                    }
                }
                try{sleep(1);}
                catch(Exception ef) {};
            }
        }
    }
}
